package com.aierjun.controller;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.aierjun.bean.RespBean;
import com.aierjun.bean.UserBean;
import com.aierjun.service.UserService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;


public class UserController implements Controller {
	private UserService UserService;

	@Override
	public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse resp) throws Exception {
		UserBean userBean=new UserBean();
		System.out.println("controller");
		userBean.setUname(req.getParameter("uname"));
		userBean.setPassword(req.getParameter("password"));
		userBean.setToken(System.currentTimeMillis() + "");
		UserService.add(userBean);
		
		RespBean respBean = new RespBean();
		respBean.setCode(200);
		respBean.setMsg("ok");
		respBean.setData(JSON.toJSONString(userBean));
		
		resp.setCharacterEncoding("UTF-8");
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(JSON.toJSONString(respBean).replace("\\", ""));
		
		
		
		return null;
	}

	public UserService getUserService() {
		return UserService;
	}

	public void setUserService(UserService userService) {
		UserService = userService;
	}
	
}
